import BaseService from './base';
import Sequelize from 'sequelize';
import db from '../models';
const Op = Sequelize.Op;

export default class IplService extends BaseService {
  constructor({ iplDao }) {
    super();
    this.iplDao = iplDao
  }

  // 获取IP
  async getIplOne () {
    try {
      const rows = await db.sequelize.query('select t_ip_list.t_ipl from t_ip_list limit 1;', {
        type: db.sequelize.QueryTypes.SELECT
      })
      return this.success('获取成功', rows);
    } catch (err) {
      return this.fail('获取失败', null, err);
    }
  }

  // 根据IP删除对应数据
  async delByIp (ipl) {
    const [err, updateIpl] = await this.iplDao.delete({
      where: {
        t_ipl: ipl.t_ipl
      }
    });
    if (err) {
      return this.fail('删除失败');
    }
    return this.success('删除成功');
  }

  // 批量添加
  async bulkIpls (ipls) {
    const [err, list] = await this.iplDao.bulkIpls(ipls);
    if (err) {
      return this.fail('批量添加失败', null, err);
    }
    return this.success('批量添加成功', list);
  }
}